package com.lalilu.lmedia.entity

import androidx.room.*
import com.lalilu.lmedia.database.Linkable
import java.util.*

@Entity(
    tableName = "song_in_playlist",
    foreignKeys = [
        ForeignKey(
            entity = LPlaylist::class,
            parentColumns = ["p_id"],
            childColumns = ["p_id"],
            onDelete = ForeignKey.CASCADE
        )
    ],
    indices = [Index(
        value = ["p_id", "s_id"],
        unique = true
    )]
)
data class SongInPlaylist(
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "s_p_id")
    var _id: Long = 0,

    @ColumnInfo(name = "p_id")
    val playlistId: Long,
    @ColumnInfo(name = "s_id")
    val mediaId: String,

    @ColumnInfo(name = "s_p_create_time")
    val time: Date = Date(),

    override var nextId: Long? = null
) : Linkable {
    override fun getLinkableId(): Long = _id

    override fun setLinkableId(id: Long) {
        _id = id
    }

    override fun getClassifyId(): Long = playlistId
}